package com.easemob.helpdesk.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Display;
import android.widget.ScrollView;

import com.easemob.helpdesk.utils.DisplayUtil;

/**
 * Created by xiaolong.wei on 2018/10/16.
 */

public class MaxHeightScrollView extends ScrollView {
    private Context mContext;
    public MaxHeightScrollView(Context context) {
        this(context,null);
    }

    public MaxHeightScrollView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public MaxHeightScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        try {
            int windowHeight = mContext.getResources().getDisplayMetrics().heightPixels;
            int outerHeight = DisplayUtil.px2dip(mContext, windowHeight)-54;
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(DisplayUtil.dip2px(mContext,outerHeight - 114),MeasureSpec.AT_MOST);
        }catch (Exception e){
            e.printStackTrace();
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
